@extends('admin.layouts.app')

@section('right-content')
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>编辑房间</legend>
    </fieldset>

    <form class="layui-form" action="">
        {{ method_field('PUT') }}
        <div class="layui-form-item">
            <label class="layui-form-label">房间名称</label>
            <div class="layui-input-inline">
                <input type="text" name="room_name" lay-verify="required" value="{{ $room->room_name }}" placeholder="请输入房间名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-inline">
                <input type="text" name="thumbnail" lay-verify="required" value="{{ $room->thumbnail }}" placeholder="请输入图标编码" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">例如: 001</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">最大数值</label>
            <div class="layui-input-inline">
                <input type="text" name="max" lay-verify="required" value="{{ $room->max }}" placeholder="请输入最大数值" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">最小数值</label>
            <div class="layui-input-inline">
                <input type="text" name="min" lay-verify="required" value="{{ $room->min }}" placeholder="请输入最小数值" autocomplete="off" class="layui-input">
            </div>
        </div>
        {{-- <div class="layui-form-item">
            <label class="layui-form-label">桌子数</label>
            <div class="layui-input-inline">
                <input type="text" name="table_count" lay-verify="required|num" value="{{ $room->table_count }}" placeholder="请输入桌子数" autocomplete="off" class="layui-input">
            </div>
        </div> --}}
        <div class="layui-form-item">
            <label class="layui-form-label">押注档次</label>
            <div class="layui-input-inline">
                <input type="text" name="jeton" lay-verify="" value="{{ $room->jeton }}" placeholder="请输入押注档次" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">五个档次用“,”分隔, 必填</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">最大下注额</label>
            <div class="layui-input-inline">
                <input type="text" name="enter_limit_max" lay-verify="required|number" value="{{ $room->enter_limit_max }}" placeholder="请输入最大下注额" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">经验基准值</label>
            <div class="layui-input-inline">
                <input type="text" name="experience_base" lay-verify="" value="{{ $room->experience_base }}" placeholder="请输入经验基准值" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">可不填</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">经验增长率</label>
            <div class="layui-input-inline">
                <input type="text" name="experience_rate" lay-verify="" value="{{ $room->experience_rate }}" placeholder="请输入经验增长率" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">可不填</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="sort_id" lay-verify="number" value="{{ $room->sort_id }}" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="radio" name="status" value="1" title="启用" @if ($room->status == 1) checked @endif>
                <input type="radio" name="status" value="0" title="停用" @if ($room->status == 0) checked @endif>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="sub" data-url="{{ route('gamerooms.update', ['id' =>
                $room->room_id]) }}">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
@endsection

@section('my-js')
<script type="text/javascript">
    layui.use(['form', 'upload', 'layer'], function(){
        var form = layui.form, upload = layui.upload, layer = layui.layer;

        $(document).on('click', '.imgClose', function(){
            $(this).parent().remove();
        });

        //执行实例
        var uploadInst = upload.render({
            elem: '#test8', //绑定元素
            method: 'post',
            accept: 'images',
            auto: false,      //不自动上传
            bindAction: '#test9',
            field: 'image',
            data: {

            },
            url: '{{ route('admin.upload.images') }}', //上传接口
            // before: function(obj){
            //       //预读本地文件示例，不支持ie8
            //     obj.preview(function(index, file, result){
            //         $('#thumbnail').attr('src', result); //图片链接（base64）
            //     });
            // },
            // choose: function(){
            //     layer.load(1);
            // },
            done: function(res){
                //上传完毕回调
                console.log(res);
                layer.closeAll('loading');
                if (res.status == 0) {
                    layer.msg(res.msg, {icon:1, time: 2000});
                    var attstr = '<img height="100" width="100" src="'+res.path+'"><input type="hidden" name="thumbnail" value="'+res.path+'"><button type="button" class="imgClose"><i class="glyphicon glyphicon-trash"></i></button>';
                    $(".imglist").empty();
                    $(".imglist").append(attstr);

                } else {
                    layer.msg(res.msg, {icon:2 , time: 2000 });
                }
            },
            error: function(){
              //请求异常回调
              alert('error');
            }
        });



        form.on('submit(sub)', function(data){
            var url = $(this).attr('data-url');
            commonAjaxSubmit(url, 'PUT');

        });
    })
</script>

@endsection